﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApFLEXCableNewAttributeViewModel
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Flexibles;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;


namespace DnProcessSimulateCommands;

public class CApFLEXCableNewAttributeViewModel : 
  ICApFLEXCableAttributeViewModel,
  ICApCableNameViewModel,
  INotifyPropertyChanged,
  ICApCableExtentDescriptor,
  ICApCableCreationModeStatus,
  ICApCableFrameStatus,
  ICApCableParameterChangeChecker
{
  private const double FORCE_PARAMETER_EPSILON = 0.01;
  private const double PARAMETER_EPSILON = 0.0001;
  private readonly CApFLEXCounter m_pendingNotificationsCounter;
  private bool m_isLicenseOn;
  private string m_name;
  private double m_length;
  private double m_radius;
  private double m_density;
  private double m_youngsModulus;
  private double m_maxTension;
  private double m_maxTwistAngle;
  private double m_minCurvatureRadius;
  private double m_maxContactForce;
  private bool m_isMaxTwistAngleLimited;
  private bool m_isMinCurvatureRadiusLimited;
  private bool m_isMaxContactForceLimited;
  private double m_fulcrumLength;
  private double m_oscillation;
  private TxCableDataResolution m_resolution;
  private string m_message;
  private CApCableStatusMessageType m_messageType;
  private double m_fulcrumStepSize;
  private double m_lengthStepSize;
  private double m_radiusStepSize;
  private double m_minCurvatureStepSize;
  private bool m_isGenerateEnabled;
  private bool m_isCloseEnabled;
  private bool m_isRemoveAttachmentEnabled;
  private bool m_isAddAttachmentEnabled;
  private bool m_isEditAttachmentEnabled;
  private bool m_isParametersExpanded;
  private bool m_isAttachmentExpanded;
  private bool m_isOptimizationExpanded;
  private bool m_isLengthOptimizationActivated;
  private bool m_isRadiusOptimizationActivated;
  private bool m_isYoungsModulusOptimizationActivated;
  private ITxLocatableObject m_startFrame;
  private ITxLocatableObject m_endFrame;
  private ITxObject m_startAttachPartTo;
  private ITxObject m_endAttachPartTo;
  private ITxLocatableObject m_passNearFrame;
  private ITxPointCloudLayer m_optimizationPointCloudLayer;
  private CUiFLEXCreationMode m_creationMode;

  public CApFLEXCableNewAttributeViewModel()
  {
    this.CableScopeStatus = new CApCableScopeStatus();
    this.FocusedPickableControl = PickableControlFocusStatus.None;
    this.m_pendingNotificationsCounter = new CApFLEXCounter();
    this.IsBeingInitialized = false;
    this.IsCableBeingGenerated = false;
  }

  public bool IsLicenseOn
  {
    get => this.m_isLicenseOn;
    set
    {
      this.m_isLicenseOn = value;
      this.NotifyPropertyChanged(nameof (IsLicenseOn));
      this.NotifyPropertyChanged("AreEquipmentParametersEnabled");
      this.NotifyPropertyChanged("IsCableParameterEnabled");
      this.NotifyPropertyChanged("IsMaxTwistAngleEnabled");
      this.NotifyPropertyChanged("IsMaxContactForceEnabled");
      this.NotifyPropertyChanged("IsMinCurvatureRadiusEnabled");
    }
  }

  public ITxCable Cable
  {
    get => this.CableScopeStatus.Cable;
    set
    {
      this.NotifyPropertyWillChange(nameof (Cable));
      this.CableScopeStatus.Cable = value;
      this.CableScopeStatus.ParentEquipment = CApCableUtility.GetParentEquipment((ITxObject) value);
      this.NotifyPropertyChanged(nameof (Cable));
      this.NotifyPropertyChanged("IsEditMode");
      this.NotifyPropertyChanged("IsCreationModeComboBoxEnabled");
      this.NotifyPropertyChanged("GenerateButtonContent");
      this.NotifyCableAttributeChanged();
    }
  }

  public ITxLocatableObject StartFrame
  {
    get => this.m_startFrame;
    set
    {
      this.NotifyPropertyWillChange(nameof (StartFrame));
      this.m_startFrame = value;
      this.NotifyPropertyChanged(nameof (StartFrame));
      this.NotifyPropertyChanged("IsEditStartAttachmentFrameEnabled");
    }
  }

  public ITxObject StartAttachPartTo
  {
    get => this.m_startAttachPartTo;
    set
    {
      this.m_startAttachPartTo = value;
      this.NotifyPropertyChanged(nameof (StartAttachPartTo));
    }
  }

  public ITxLocatableObject EndFrame
  {
    get => this.m_endFrame;
    set
    {
      this.NotifyPropertyWillChange(nameof (EndFrame));
      this.m_endFrame = value;
      this.NotifyPropertyChanged(nameof (EndFrame));
      this.NotifyPropertyChanged("IsEditEndAttachmentFrameEnabled");
    }
  }

  public ITxObject EndAttachPartTo
  {
    get => this.m_endAttachPartTo;
    set
    {
      this.m_endAttachPartTo = value;
      this.NotifyPropertyChanged(nameof (EndAttachPartTo));
    }
  }

  public ITxLocatableObject PassNearFrame
  {
    get => this.m_passNearFrame;
    set
    {
      this.NotifyPropertyWillChange(nameof (PassNearFrame));
      this.m_passNearFrame = value;
      this.NotifyPropertyChanged(nameof (PassNearFrame));
    }
  }

  public ITxPointCloudLayer OptimizationPointCloudLayer
  {
    get => this.m_optimizationPointCloudLayer;
    set
    {
      this.NotifyPropertyWillChange(nameof (OptimizationPointCloudLayer));
      this.m_optimizationPointCloudLayer = value;
      this.NotifyPropertyChanged(nameof (OptimizationPointCloudLayer));
    }
  }

  public PickableControlFocusStatus FocusedPickableControl { get; set; }

  public bool IsFrameCtrlStartFocused
  {
    get => this.FocusedPickableControl == PickableControlFocusStatus.StartFrame;
  }

  public bool IsFrameCtrlEndFocused
  {
    get => this.FocusedPickableControl == PickableControlFocusStatus.EndFrame;
  }

  public bool IsFrameCtrlPassNearFocused
  {
    get => this.FocusedPickableControl == PickableControlFocusStatus.PassNearFrame;
  }

  public bool IsPointCloudLayerCtrlOptimizationFocused
  {
    get => this.FocusedPickableControl == PickableControlFocusStatus.OptimizationPointCloudLayer;
  }

  public double RetractSystemCurrentMaxRetractedLength
  {
    get
    {
      double maxRetractedLength = 0.0;
      if (this.AttachmentDataList.Find((Predicate<CApFLEXAttachment>) (a => a is CApFLEXRetractSystemAttachment)) is CApFLEXRetractSystemAttachment systemAttachment)
        maxRetractedLength = systemAttachment.MaxRetractedLength;
      return maxRetractedLength;
    }
    set
    {
    }
  }

  public string CableName
  {
    get => this.m_name;
    set
    {
      this.m_name = value;
      this.NotifyPropertyChanged(nameof (CableName));
    }
  }

  public double Length
  {
    get => this.m_length;
    set
    {
      this.m_length = value;
      this.UpdateEndLocatedAttachmentLengthFromStart(new Action<string>(this.NotifyPropertyChanged));
      this.NotifyPropertyChanged(nameof (Length));
    }
  }

  public double Radius
  {
    get => this.m_radius;
    set
    {
      this.m_radius = value;
      this.NotifyPropertyChanged(nameof (Radius));
    }
  }

  public double Density
  {
    get => this.m_density;
    set
    {
      this.m_density = value;
      this.NotifyPropertyChanged(nameof (Density));
    }
  }

  public double YoungsModulus
  {
    get => this.m_youngsModulus;
    set
    {
      this.m_youngsModulus = value;
      this.NotifyPropertyChanged(nameof (YoungsModulus));
    }
  }

  public double MaxTension
  {
    get => this.m_maxTension;
    set
    {
      this.m_maxTension = value;
      this.NotifyPropertyChanged(nameof (MaxTension));
    }
  }

  public double MaxTwistAngle
  {
    get => this.m_maxTwistAngle;
    set
    {
      this.m_maxTwistAngle = value;
      this.NotifyPropertyChanged(nameof (MaxTwistAngle));
    }
  }

  public double MinCurvatureRadius
  {
    get => this.m_minCurvatureRadius;
    set
    {
      this.m_minCurvatureRadius = value;
      this.NotifyPropertyChanged(nameof (MinCurvatureRadius));
    }
  }

  public double MaxContactForce
  {
    get => this.m_maxContactForce;
    set
    {
      this.m_maxContactForce = value;
      this.NotifyPropertyChanged(nameof (MaxContactForce));
    }
  }

  public bool IsEditStartAttachmentFrameEnabled
  {
    get => this.m_startFrame != null && this.AreEquipmentParametersEnabled;
  }

  public bool IsEditEndAttachmentFrameEnabled
  {
    get => this.m_endFrame != null && this.AreEquipmentParametersEnabled;
  }

  public bool IsMaxTwistAngleLimited
  {
    get => this.m_isMaxTwistAngleLimited;
    set
    {
      this.m_isMaxTwistAngleLimited = value;
      this.NotifyPropertyChanged(nameof (IsMaxTwistAngleLimited));
      this.NotifyPropertyChanged("IsMaxTwistAngleEnabled");
    }
  }

  public bool IsMaxTwistAngleEnabled => this.IsMaxTwistAngleLimited && this.IsCableParameterEnabled;

  public bool IsMinCurvatureRadiusLimited
  {
    get => this.m_isMinCurvatureRadiusLimited;
    set
    {
      this.m_isMinCurvatureRadiusLimited = value;
      this.NotifyPropertyChanged(nameof (IsMinCurvatureRadiusLimited));
      this.NotifyPropertyChanged("IsMinCurvatureRadiusEnabled");
    }
  }

  public bool IsMinCurvatureRadiusEnabled
  {
    get => this.IsMinCurvatureRadiusLimited && this.IsCableParameterEnabled;
  }

  public bool IsMaxContactForceLimited
  {
    get => this.m_isMaxContactForceLimited;
    set
    {
      this.m_isMaxContactForceLimited = value;
      this.NotifyPropertyChanged(nameof (IsMaxContactForceLimited));
      this.NotifyPropertyChanged("IsMaxContactForceEnabled");
    }
  }

  public bool IsMaxContactForceEnabled
  {
    get => this.IsMaxContactForceLimited && this.IsCableParameterEnabled;
  }

  public double FulcrumLength
  {
    get => this.m_fulcrumLength;
    set
    {
      this.m_fulcrumLength = value;
      this.NotifyPropertyChanged(nameof (FulcrumLength));
    }
  }

  public double Oscillation
  {
    get => this.m_oscillation;
    set
    {
      this.m_oscillation = value;
      this.NotifyPropertyChanged(nameof (Oscillation));
    }
  }

  public TxCableDataResolution Resolution
  {
    get => this.m_resolution;
    set
    {
      this.m_resolution = value;
      this.NotifyPropertyChanged(nameof (Resolution));
    }
  }

  public bool IsLengthOptimizationActivated
  {
    get => this.m_isLengthOptimizationActivated;
    set
    {
      if (value == this.m_isLengthOptimizationActivated)
        return;
      this.m_isLengthOptimizationActivated = value;
      this.NotifyPropertyChanged(nameof (IsLengthOptimizationActivated));
    }
  }

  public bool IsRadiusOptimizationActivated
  {
    get => this.m_isRadiusOptimizationActivated;
    set
    {
      if (value == this.m_isRadiusOptimizationActivated)
        return;
      this.m_isRadiusOptimizationActivated = value;
      this.NotifyPropertyChanged(nameof (IsRadiusOptimizationActivated));
    }
  }

  public bool IsYoungsModulusOptimizationActivated
  {
    get => this.m_isYoungsModulusOptimizationActivated;
    set
    {
      if (value == this.m_isYoungsModulusOptimizationActivated)
        return;
      this.m_isYoungsModulusOptimizationActivated = value;
      this.NotifyPropertyChanged(nameof (IsYoungsModulusOptimizationActivated));
    }
  }

  public List<CApFLEXAttachment> AttachmentDataList { get; set; }

  private List<TxCableAttachment> TxAttachments
  {
    get
    {
      return this.AttachmentDataList.Select<CApFLEXAttachment, TxCableAttachment>((Func<CApFLEXAttachment, TxCableAttachment>) (a => a.Attachment)).ToList<TxCableAttachment>();
    }
  }

  public double RadiusStepSize
  {
    get => this.m_radiusStepSize;
    set
    {
      this.m_radiusStepSize = value;
      this.NotifyPropertyChanged(nameof (RadiusStepSize));
    }
  }

  public double LengthStepSize
  {
    get => this.m_lengthStepSize;
    set
    {
      this.m_lengthStepSize = value;
      this.NotifyPropertyChanged(nameof (LengthStepSize));
    }
  }

  public double FulcrumStepSize
  {
    get => this.m_fulcrumStepSize;
    set
    {
      this.m_fulcrumStepSize = value;
      this.NotifyPropertyChanged(nameof (FulcrumStepSize));
    }
  }

  public double MinCurvatureStepSize
  {
    get => this.m_minCurvatureStepSize;
    set
    {
      this.m_minCurvatureStepSize = value;
      this.NotifyPropertyChanged(nameof (MinCurvatureStepSize));
    }
  }

  public CApCableStatusAnalysis CableStatusAnalysis { get; set; }

  public string Message
  {
    get => this.m_message;
    set
    {
      this.m_message = value;
      this.NotifyPropertyChanged(nameof (Message));
    }
  }

  public CApCableStatusMessageType StatusMessageType
  {
    get => this.m_messageType;
    set
    {
      this.m_messageType = value;
      this.NotifyPropertyChanged(nameof (StatusMessageType));
    }
  }

  public bool IsCreationModeComboBoxEnabled
  {
    get => this.m_creationMode == CUiFLEXCreationMode.FROM_POINT_CLOUD || !this.IsEditMode;
  }

  public bool IsGenerateEnabled
  {
    get => this.m_isGenerateEnabled;
    set
    {
      this.m_isGenerateEnabled = value;
      this.NotifyPropertyChanged(nameof (IsGenerateEnabled));
    }
  }

  public bool IsCloseEnabled
  {
    get => this.m_isCloseEnabled;
    set
    {
      this.m_isCloseEnabled = value;
      this.NotifyPropertyChanged(nameof (IsCloseEnabled));
    }
  }

  public bool IsOptimizeEnabled
  {
    get
    {
      return TxFeatureManager.CheckFeature("CABLE_STIFFNESS_OPTIMIZER") && this.m_optimizationPointCloudLayer != null;
    }
  }

  public bool IsRemoveAttachmentEnabled
  {
    get => this.m_isRemoveAttachmentEnabled && this.AreEquipmentParametersEnabled;
    set
    {
      this.m_isRemoveAttachmentEnabled = value;
      this.NotifyPropertyChanged(nameof (IsRemoveAttachmentEnabled));
      this.NotifyPropertyChanged("AreEquipmentParametersEnabled");
    }
  }

  public bool IsAddAttachmentEnabled
  {
    get => this.m_isAddAttachmentEnabled && this.AreEquipmentParametersEnabled;
    set
    {
      this.m_isAddAttachmentEnabled = value;
      this.NotifyPropertyChanged(nameof (IsAddAttachmentEnabled));
      this.NotifyPropertyChanged("AreEquipmentParametersEnabled");
    }
  }

  public bool IsEditAttachmentEnabled
  {
    get => this.m_isEditAttachmentEnabled;
    set
    {
      this.m_isEditAttachmentEnabled = value;
      this.NotifyPropertyChanged(nameof (IsEditAttachmentEnabled));
    }
  }

  public bool IsEditMode
  {
    get => this.Cable != null;
    set
    {
    }
  }

  public string GenerateButtonContent
  {
    get
    {
      return !this.IsEditMode ? CApFLEXStringTable.FlexGenerateButton : CApFLEXStringTable.FlexRegenerateButton;
    }
  }

  public bool IsCableEditable
  {
    get => this.Cable == null || this.Cable.IsOpenForModeling;
    set
    {
    }
  }

  public bool IsEquipmentEditable
  {
    private get => this.CableScopeStatus.IsCableInEquipment;
    set
    {
      this.NotifyPropertyChanged("AreEquipmentParametersEnabled");
      this.NotifyPropertyChanged("IsCableParameterEnabled");
      this.NotifyPropertyChanged("IsAddAttachmentEnabled");
      this.NotifyPropertyChanged("IsRemoveAttachmentEnabled");
    }
  }

  public CApCableScopeStatus CableScopeStatus { get; }

  public bool AreEquipmentParametersEnabled
  {
    get
    {
      if (!this.IsLicenseOn)
        return false;
      return !this.CableScopeStatus.IsCableInEquipment || this.CableScopeStatus.CableEquipmentModelingStatus != CApCableScopeStatus.ECableEquipmentModelingScope.NotOpenForModeling;
    }
  }

  public bool IsCableParameterEnabled
  {
    get
    {
      if (!this.IsLicenseOn)
        return false;
      return !this.IsEditMode || this.CableScopeStatus.IsCableOpenForModeling;
    }
  }

  public bool IsParametersExpanded
  {
    get => this.m_isParametersExpanded;
    set
    {
      this.m_isParametersExpanded = value;
      this.NotifyPropertyChanged(nameof (IsParametersExpanded));
    }
  }

  public bool IsAttachmentExpanded
  {
    get => this.m_isAttachmentExpanded;
    set
    {
      this.m_isAttachmentExpanded = value;
      this.NotifyPropertyChanged(nameof (IsAttachmentExpanded));
    }
  }

  public bool IsOptimizationExpanded
  {
    get => this.m_isOptimizationExpanded;
    set
    {
      this.m_isOptimizationExpanded = value;
      this.NotifyPropertyChanged(nameof (IsOptimizationExpanded));
    }
  }

  public CUiFLEXCreationMode CreationMode
  {
    get => this.m_creationMode;
    set
    {
      this.m_creationMode = value;
      this.NotifyPropertyChanged(nameof (CreationMode));
      this.NotifyPropertyChanged("IsCreationModeComboBoxEnabled");
    }
  }

  public bool IsCreationParameter(string propertyName)
  {
    return propertyName == "CableName" || propertyName == "AttachmentDataList" || propertyName == "StartFrame" || propertyName == "EndFrame" || propertyName == "PassNearFrame" || propertyName == "OptimizationPointCloudLayer" || propertyName == "Length" || propertyName == "Radius" || propertyName == "Density" || propertyName == "YoungsModulus" || propertyName == "FulcrumLength" || propertyName == "Oscillation" || propertyName == "MaxTension" || propertyName == "MaxTwistAngle" || propertyName == "MaxContactForce" || propertyName == "MinCurvatureRadius" || propertyName == "IsMaxTwistAngleLimited" || propertyName == "IsMaxContactForceLimited" || propertyName == "IsMinCurvatureRadiusLimited";
  }

  public bool IsFrameParameter(string propertyName)
  {
    return propertyName == "StartFrame" || propertyName == "EndFrame" || propertyName == "PassNearFrame" || propertyName == "AttachmentDataList" || propertyName == "StartAttachPartTo" || propertyName == "EndAttachPartTo";
  }

  public bool IsOptimizationParameter(string propertyName)
  {
    return propertyName == "OptimizationPointCloudLayer" || propertyName == "IsLengthOptimizationActivated" || propertyName == "IsRadiusOptimizationActivated" || propertyName == "IsYoungsModulusOptimizationActivated";
  }

  public bool HasParameterChanged()
  {
    switch (this.CreationMode)
    {
      case CUiFLEXCreationMode.MANUAL:
        return this.HasParameterChangedForParameterCreationMode();
      case CUiFLEXCreationMode.FROM_POINT_CLOUD:
        return this.HasParameterChangedForPointCloudCreationMode();
      default:
        throw new NotImplementedException();
    }
  }

  private bool HasParameterChangedForParameterCreationMode()
  {
    bool flag = this.Cable == null;
    if (!flag)
    {
      try
      {
        TxCableData cableData = this.Cable.CableData;
        flag = CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.Length, this.Length, 0.0001) || CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.Radius, this.Radius, 0.0001) || CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.Density, this.Density, 0.0001) || CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.YoungsModulus, this.YoungsModulus, 0.0001) || CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.FulcrumLength, this.FulcrumLength, 0.0001) || CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.MaximumAllowedTension, this.MaxTension, 0.01) || CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.MaximumAllowedTwistRate, this.MaxTwistAngle, 0.0001) || CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.MaximumAllowedContactForce, this.MaxContactForce, 0.01) || CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.MinimumAllowedCurvatureRadius, this.MinCurvatureRadius, 0.0001) || cableData.IsTwistRateLimited != this.IsMaxTwistAngleLimited || cableData.IsContactForceLimited != this.IsMaxContactForceLimited || cableData.IsCurvatureRadiusLimited != this.IsMinCurvatureRadiusLimited || cableData.Oscillation != this.Oscillation || cableData.PassNearFrame != this.PassNearFrame || ((ITxObject) this.Cable).Name != this.CableName || this.Cable.StartFrame != this.StartFrame || this.Cable.StartFrame.AttachmentParent != this.StartAttachPartTo || this.Cable.EndFrame != this.EndFrame || this.Cable.EndFrame.AttachmentParent != this.EndAttachPartTo || CApFLEXCableNewAttributeViewModel.AreAttachmentsDifferent((IEnumerable<TxCableAttachment>) cableData.Attachments, (IEnumerable<TxCableAttachment>) this.TxAttachments);
      }
      catch (FormatException ex)
      {
        flag = false;
      }
    }
    return flag;
  }

  private bool HasParameterChangedForPointCloudCreationMode()
  {
    bool flag = this.Cable == null;
    if (!flag)
    {
      try
      {
        TxCableData cableData = this.Cable.CableData;
        flag = CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.Length, this.Length, 0.0001) || CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.Radius, this.Radius, 0.0001) || CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.Density, this.Density, 0.0001) || CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.YoungsModulus, this.YoungsModulus, 0.0001) || CApFLEXCableNewAttributeViewModel.AreDoublesDifferent(cableData.FulcrumLength, this.FulcrumLength, 0.0001) || ((ITxObject) this.Cable).Name != this.CableName || this.Cable.StartFrame != this.StartFrame || this.Cable.StartFrame.AttachmentParent != this.StartAttachPartTo || this.Cable.EndFrame != this.EndFrame || this.Cable.EndFrame.AttachmentParent != this.EndAttachPartTo;
      }
      catch (FormatException ex)
      {
        flag = false;
      }
    }
    return flag;
  }

  public void AttachmentViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
  {
    if (!(e.PropertyName == "LengthFromStart"))
      return;
    this.NotifyPropertyChanged("AttachmentDataList");
  }

  public void SetLengthNoEventSent(double value)
  {
    if (this.AreNotificationsPending())
      return;
    this.m_length = value;
    this.UpdateEndLocatedAttachmentLengthFromStart(new Action<string>(this.NotifyPropertyChanging));
    this.NotifyPropertyChanging("Length");
  }

  public void SetRadiusNoEventSent(double value)
  {
    if (this.AreNotificationsPending())
      return;
    this.m_radius = value;
    this.NotifyPropertyChanging("Radius");
  }

  public void SetDensityNoEventSent(double value)
  {
    if (this.AreNotificationsPending())
      return;
    this.m_density = value;
    this.NotifyPropertyChanging("Density");
  }

  public void SeYoungsModulusNoEventSent(double value)
  {
    if (this.AreNotificationsPending())
      return;
    this.m_youngsModulus = value;
    this.NotifyPropertyChanging("YoungsModulus");
  }

  public void SetFulcrumNoEventSent(double value)
  {
    if (this.AreNotificationsPending())
      return;
    this.m_fulcrumLength = value;
    this.NotifyPropertyChanging("FulcrumLength");
  }

  public void SetMaxTentionNoEventSent(double value)
  {
    if (this.AreNotificationsPending())
      return;
    this.m_maxTension = value;
    this.NotifyPropertyChanging("MaxTension");
  }

  public void SetMaxTwistAngleNoEventSent(double value)
  {
    if (this.AreNotificationsPending())
      return;
    this.m_maxTwistAngle = value;
    this.NotifyPropertyChanging("MaxTwistAngle");
  }

  public void SetMaxContactForceNoEventSent(double value)
  {
    if (this.AreNotificationsPending())
      return;
    this.m_maxContactForce = value;
    this.NotifyPropertyChanging("MaxContactForce");
  }

  public void SetMinCurvatureRadiusNoEventSent(double value)
  {
    if (this.AreNotificationsPending())
      return;
    this.m_minCurvatureRadius = value;
    this.NotifyPropertyChanging("MinCurvatureRadius");
  }

  public void AddAttachment(CApFLEXAttachment attachment)
  {
    this.AttachmentDataList.Add(attachment);
    this.NotifyPropertyChanged("AttachmentDataList");
  }

  public void RemoveAttachment(CApFLEXAttachment attachment)
  {
    this.AttachmentDataList.Remove(attachment);
    this.NotifyPropertyChanged("AttachmentDataList");
  }

  public void ClearAttachments()
  {
    this.AttachmentDataList.Clear();
    this.NotifyPropertyChanged("AttachmentDataList");
  }

  public void ChangeStartLocatedAttachmentFrame()
  {
    if (this.AttachmentDataList == null || this.StartFrame == null)
      return;
    CApFLEXAttachment capFlexAttachment = this.AttachmentDataList.Find((Predicate<CApFLEXAttachment>) (a => a.Location == CApFLEXAttachmentLocation.Start));
    if (capFlexAttachment == null || capFlexAttachment.FixedFrame == this.StartFrame)
      return;
    capFlexAttachment.FixedFrame = this.StartFrame;
    this.NotifyPropertyChanged("AttachmentDataList");
  }

  public void ChangeEndLocatedAttachmentFrame()
  {
    if (this.AttachmentDataList == null || this.EndFrame == null)
      return;
    CApFLEXAttachment capFlexAttachment = this.AttachmentDataList.Find((Predicate<CApFLEXAttachment>) (a => a.Location == CApFLEXAttachmentLocation.End));
    if (capFlexAttachment == null || capFlexAttachment.FixedFrame == this.EndFrame)
      return;
    capFlexAttachment.FixedFrame = this.EndFrame;
    this.NotifyPropertyChanged("AttachmentDataList");
  }

  private void UpdateEndLocatedAttachmentLengthFromStart(Action<string> notificationFunction)
  {
    if (this.AttachmentDataList == null)
      return;
    CApFLEXAttachment capFlexAttachment = this.AttachmentDataList.Find((Predicate<CApFLEXAttachment>) (a => a.Location == CApFLEXAttachmentLocation.End));
    if (capFlexAttachment == null)
      return;
    capFlexAttachment.LengthFromStart = this.Length;
    notificationFunction("AttachmentDataList");
  }

  public void UpdateMaxRetractedLength()
  {
    if (!(this.AttachmentDataList.Find((Predicate<CApFLEXAttachment>) (a => a.AttachmentType == CApFLEXAttachmentType.RetractSystemType1)) is CApFLEXRetractSystemAttachmentType1 systemAttachmentType1))
      return;
    if (this.Length < this.RetractSystemCurrentMaxRetractedLength)
    {
      systemAttachmentType1.MaxRetractedLength = this.Length;
      this.NotifyPropertyChanged("AttachmentDataList");
    }
    else
    {
      if (systemAttachmentType1.MaxRetractedLength >= this.RetractSystemCurrentMaxRetractedLength)
        return;
      systemAttachmentType1.MaxRetractedLength = this.RetractSystemCurrentMaxRetractedLength;
      this.NotifyPropertyChanged("AttachmentDataList");
    }
  }

  public void UpdateEndAttachmentLengthFromStart()
  {
    CApFLEXAttachment capFlexAttachment = this.AttachmentDataList.Find((Predicate<CApFLEXAttachment>) (a => a.Location == CApFLEXAttachmentLocation.End));
    if (capFlexAttachment == null)
      return;
    capFlexAttachment.LengthFromStart = this.Length;
    this.NotifyPropertyChanged("AttachmentDataList");
  }

  public List<CApFLEXAttachment> RawAttachmentList() => this.AttachmentDataList;

  public void InitAttachmentList() => this.AttachmentDataList = new List<CApFLEXAttachment>();

  public bool IsAttachmentListNull() => this.AttachmentDataList == null;

  public int CountAttachments() => this.AttachmentDataList.Count;

  public void SetAttachmentList(List<CApFLEXAttachment> attachments)
  {
    this.AttachmentDataList = attachments;
    this.NotifyPropertyChanged("AttachmentDataList");
  }

  public FrameSelectionType ComputeAlreadyDefinedFrameSelectionType(
    ITxLocatableObject frame,
    IEnumerable<FrameSelectionType> frameSelectionTypes)
  {
    if (frameSelectionTypes == null)
      throw new ArgumentNullException(nameof (frameSelectionTypes));
    FrameSelectionType frameSelectionType = FrameSelectionType.None;
    bool flag = false;
    IEnumerator<FrameSelectionType> enumerator = frameSelectionTypes.GetEnumerator();
    while (!flag && enumerator.MoveNext())
      flag = this.IsFrameAlreadyDefined(frame, enumerator.Current);
    if (flag)
      frameSelectionType = enumerator.Current;
    return frameSelectionType;
  }

  public bool IsFrameWithinSameScopeAsCable(ITxLocatableObject frame)
  {
    if (frame == null)
      return false;
    return !this.CableScopeStatus.IsCableInEquipment || CApCableUtility.IsObjectInsideEquipment((ITxObject) frame, this.CableScopeStatus.ParentEquipment);
  }

  public ITxCableOptimizationData ComputeOptimizationData()
  {
    ITxCableOptimizationData optimizationData = (ITxCableOptimizationData) null;
    if (TxFeatureManager.CheckFeature("CABLE_STIFFNESS_OPTIMIZER") && this.CreationMode == CUiFLEXCreationMode.FROM_POINT_CLOUD && this.OptimizationPointCloudLayer != null)
    {
      optimizationData = (ITxCableOptimizationData) new TxCableOptimizationData()
      {
        PointCloudLayer = this.OptimizationPointCloudLayer
      };
      if (this.IsLengthOptimizationActivated)
        optimizationData.AddParameterToOptimize((TxCableOptimizableParameter) 0);
      if (this.IsRadiusOptimizationActivated)
        optimizationData.AddParameterToOptimize((TxCableOptimizableParameter) 1);
      if (this.IsYoungsModulusOptimizationActivated)
        optimizationData.AddParameterToOptimize((TxCableOptimizableParameter) 2);
    }
    return optimizationData;
  }

  public bool IsBeingInitialized { get; set; }

  public bool IsCableBeingGenerated { get; set; }

  private bool IsFrameAlreadyDefined(
    ITxLocatableObject frame,
    FrameSelectionType frameSelectionType)
  {
    bool flag = false;
    switch (frameSelectionType)
    {
      case FrameSelectionType.StartFrame:
        flag = this.IsFrameAlreadyDefinedAsStartFrame(frame);
        break;
      case FrameSelectionType.EndFrame:
        flag = this.IsFrameAlreadyDefinedAsEndFrame(frame);
        break;
      case FrameSelectionType.PassNearFrame:
        flag = this.IsFrameAlreadyDefinedAsPassNearFrame(frame);
        break;
      case FrameSelectionType.AttachmentFrame:
        flag = this.IsFrameAlreadyDefinedAsAttachmentFrame(frame);
        break;
    }
    return flag;
  }

  private bool IsFrameAlreadyDefinedAsStartFrame(ITxLocatableObject frame)
  {
    return frame == this.StartFrame;
  }

  private bool IsFrameAlreadyDefinedAsEndFrame(ITxLocatableObject frame) => frame == this.EndFrame;

  private bool IsFrameAlreadyDefinedAsPassNearFrame(ITxLocatableObject frame)
  {
    return frame == this.PassNearFrame;
  }

  private bool IsFrameAlreadyDefinedAsAttachmentFrame(ITxLocatableObject frame)
  {
    bool flag = false;
    IEnumerator<CApFLEXAttachment> enumerator = this.AttachmentDataList.Where<CApFLEXAttachment>((Func<CApFLEXAttachment, bool>) (a => a.Location == CApFLEXAttachmentLocation.AlongCable)).GetEnumerator();
    while (!flag && enumerator.MoveNext())
      flag = enumerator.Current.DoesUseFrame(frame);
    return flag;
  }

  private static bool AreAttachmentsDifferent(
    IEnumerable<TxCableAttachment> cableAttachments,
    IEnumerable<TxCableAttachment> modelAttachments)
  {
    bool flag = cableAttachments.Count<TxCableAttachment>() == modelAttachments.Count<TxCableAttachment>();
    IEnumerator<TxCableAttachment> enumerator1 = cableAttachments.GetEnumerator();
    IEnumerator<TxCableAttachment> enumerator2 = modelAttachments.GetEnumerator();
    while (flag && enumerator1.MoveNext() && enumerator2.MoveNext())
      flag = enumerator1.Current.Equals(enumerator2.Current);
    return !flag;
  }

  private static bool AreDoublesDifferent(
    double firstDouble,
    double secondDouble,
    double tolerance)
  {
    return Math.Abs(firstDouble - secondDouble) > tolerance;
  }

  public event PropertyChangedEventHandler PropertyChanged;

  protected void NotifyPropertyChanged(string info)
  {
    using (new CApFLEXCounterIncrementSession(this.m_pendingNotificationsCounter))
    {
      PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
      if (propertyChanged == null)
        return;
      propertyChanged((object) this, new PropertyChangedEventArgs(info));
    }
  }

  public event PropertyChangedEventHandler PropertyWillChange;

  protected void NotifyPropertyWillChange(string info)
  {
    using (new CApFLEXCounterIncrementSession(this.m_pendingNotificationsCounter))
    {
      PropertyChangedEventHandler propertyWillChange = this.PropertyWillChange;
      if (propertyWillChange == null)
        return;
      propertyWillChange((object) this, new PropertyChangedEventArgs(info));
    }
  }

  public event PropertyChangedEventHandler PropertyChanging;

  private void NotifyPropertyChanging(string info)
  {
    using (new CApFLEXCounterIncrementSession(this.m_pendingNotificationsCounter))
    {
      PropertyChangedEventHandler propertyChanging = this.PropertyChanging;
      if (propertyChanging == null)
        return;
      propertyChanging((object) this, new PropertyChangedEventArgs(info));
    }
  }

  public event PropertyChangedEventHandler PropertyAttributeChanged;

  public void NotifyPropertyAttributeChanged(string propertyName)
  {
    using (new CApFLEXCounterIncrementSession(this.m_pendingNotificationsCounter))
    {
      PropertyChangedEventHandler attributeChanged = this.PropertyAttributeChanged;
      if (attributeChanged == null)
        return;
      attributeChanged((object) this, new PropertyChangedEventArgs(propertyName));
    }
  }

  private bool AreNotificationsPending() => this.m_pendingNotificationsCounter.Value != 0;

  public void NotifyCableAttributeChanged()
  {
    this.NotifyPropertyChanged("Cable");
    this.NotifyPropertyChanged("IsCableEditable");
    this.NotifyPropertyChanged("AreEquipmentParametersEnabled");
    this.NotifyPropertyChanged("IsCableParameterEnabled");
    this.NotifyPropertyChanged("IsMinCurvatureRadiusEnabled");
    this.NotifyPropertyChanged("IsMaxTwistAngleEnabled");
    this.NotifyPropertyChanged("IsMaxContactForceEnabled");
    this.NotifyPropertyChanged("IsAddAttachmentEnabled");
    this.NotifyPropertyChanged("IsRemoveAttachmentEnabled");
  }
}
